package communication.common.command;

import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.ext.shell.command.CommandRegistry;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

import java.util.Map;

/**
 *  vertx的命令行
 * @author mac
 */
@Slf4j
@NoArgsConstructor
public class VertxCommand {

    @Autowired
    private ApplicationContext applicationContext;

    @Autowired
    private Vertx vertx;


    /**
     * 初始化一个 command
     */
    public Future initCommand()  {
        return Future.future(e->{
            Map<String, BaseCommandCli> beansOfType = applicationContext.getBeansOfType(BaseCommandCli.class);
            CommandRegistry registry = CommandRegistry.getShared(vertx);
            for (BaseCommandCli cli: beansOfType.values()) {
                registry.registerCommand(cli.getCliBuilder().build(vertx));
            }
        });
    }



}
